package com.hzhq.contract.service.impl;

import com.hzhq.contract.bean.dto.UserRoleDTO;
import com.hzhq.contract.bean.entity.User;
import com.hzhq.contract.bean.entity.UserRole;
import com.hzhq.contract.convert.UserRoleConvertBasic;
import com.hzhq.contract.repo.AdminRepository;
import com.hzhq.contract.repo.UserRepository;
import com.hzhq.contract.repo.UserRoleRepository;
import com.hzhq.contract.service.UserRoleService;
import com.hzhq.contract.status.DefaultValue;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: hzhq1255
 * @Mail: hzhq1255@163.com
 * @Date: 2021/5/3 20:07
 * @Desc:
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    UserRoleRepository userRoleRepo;

    @Autowired
    UserRepository userRepo;

    @Autowired
    AdminRepository adminRepo;

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public List<UserRoleDTO> getUserRoleByUserId(ObjectId userId) {
        User user = userRepo.findByUserIdAndDeleted(userId, DefaultValue.NOT_DELETED).orElse(null);
        return userRoleRepo.findByUserAndDeleted(user,DefaultValue.NOT_DELETED).stream()
                .map(UserRoleConvertBasic.INSTANCE::poToDto).collect(Collectors.toList());
    }

    @Override
    public List<UserRoleDTO> getUserRoleByUserName(String userName) {
        return null;
    }

    @Override
    public List<UserRoleDTO> getUserRoleByAdminId(ObjectId adminId) {
        return null;
    }

    @Override
    public List<UserRoleDTO> getUserRoleByAdminName(String adminName) {
        return null;
    }

    @Override
    public UserRoleDTO saveUserRoleById(String userId, String adminId, String roleId) {
        return null;
    }

    @Override
    public UserRoleDTO saveUserRoleByName(String userName, String adminName, String roleName) {
        return null;
    }
}
